#include "ce_core.h"
#include "ce_tester.h"

using namespace CETester;

CE_TESTCASE(Buf) {
    ce_chain_t         *alloc_head = NULL;
    ce_chain_t         *use_head = NULL;

    ce_chain_pool_init(4096);
    printf("!!!!!!!!!!!!!!!!!!!!!test1\n");

    for (int i = 0; i < 20; ++i) {
        ce_chain_get(&alloc_head, NULL);
    }
    printf("!!!!!!!!!!!!!!!!!!!!!test2 %d\n", alloc_head->ref);

    ce_chain_acquire(alloc_head);
    printf("!!!!!!!!!!!!!!!!!!!!!test3 %d\n", alloc_head->ref);
    for (ce_chain_t *p = alloc_head; p != NULL; p = p->next) {
        ce_chain_get(&use_head, &p->in_buf);
    }
    printf("!!!!!!!!!!!!!!!!!!!!!test4 %d\n", use_head->ref);

    ce_chain_put_all(alloc_head);
    printf("!!!!!!!!!!!!!!!!!!!!!test5 %d\n", alloc_head->ref);
    for (ce_chain_t *p = use_head; p != NULL; p = ce_chain_put(p));
    printf("!!!!!!!!!!!!!!!!!!!!!test6 %d\n", use_head->ref);

    ce_chain_put_all(alloc_head);
    printf("!!!!!!!!!!!!!!!!!!!!!test7 %d\n", alloc_head->ref);
}

int main() {
    RunAllTester();
}
